import { isUrl } from '../utils/utils';

const menuData = [
  // dashboard
  {
    name: 'Dashboard',
    icon: 'dashboard',
    path: 'dashboard',
    children: [
      {
        name: '工作台',
        path: 'workplace',
        // hideInBreadcrumb: true,
        // hideInMenu: true,
      },
      // {
      //   name: '分析页',
      //   path: 'analysis',
      // },
      // {
      //   name: '监控页',
      //   path: 'monitor',
      // },
    ],
  },
  // cms
  {
    name: '新闻管理',
    icon: 'form',
    path: 'cms',
    children: [
      {
        name: '栏目管理',
        path: 'category',
      },
      {
        name: '文章管理',
        path: 'article',
      },
      {
        name: '文章管理',
        path: 'article_add',
        hideInMenu: true,
      },
      {
        name: '文章管理',
        path: 'article_eidt',
        hideInMenu: true,
      },
      {
        name: '评论管理',
        path: 'comment',
      },
      {
        name: '素材管理',
        path: 'material',
      },
    ],
  },
  // system
  {
    name: '系统管理',
    icon: 'setting',
    path: 'system',
    children: [
      {
        name: '用户管理',
        path: 'user',
      },
      {
        name: '角色管理',
        path: 'role',
      },
      {
        name: '资源管理',
        path: 'resource',
      },
      {
        name: '菜单管理',
        path: 'menu',
      },
    ],
  },
  // user
  {
    name: '账户',
    icon: 'user',
    path: 'user',
    authority: 'guest',
    children: [
      {
        name: '登录',
        path: 'login',
      },
      {
        name: '注册',
        path: 'register',
      },
      {
        name: '注册结果',
        path: 'register-result',
      },
    ],
  },
];

function formatter(data, parentPath = '/', parentAuthority) {
  return data.map(item => {
    let { path } = item;
    if (!isUrl(path)) {
      path = parentPath + item.path;
    }
    const result = {
      ...item,
      path,
      authority: item.authority || parentAuthority,
    };
    if (item.children) {
      result.children = formatter(item.children, `${parentPath}${item.path}/`, item.authority);
    }
    return result;
  });
}

export const getMenuData = () => formatter(menuData);
